package com.takanafu.haru.code{
	import com.takanafu.haru.core.GlobalManager;
	
	public class CodeNew extends CodeBase{
		private var symbol:CodeSymbol;
		private var block:CodeBlock;
		
		public function CodeNew(sym:CodeSymbol,blk:CodeBlock){
			this.symbol = sym;
			this.block = blk;
		}
		
		override public function run():CodeBase{
			var c:CodeBase = GlobalManager.getSymbolValue(this.symbol);
			
			if(c == null){
				throw new Error("no object");
			}
			if(c is CodeObject == false){
				throw new Error("not object");
			}
			var obj:CodeObject = new CodeObject(c as CodeObject);
			
			if(this.block != null){
				GlobalManager.pushObject(obj);
				this.block.run();
				GlobalManager.popObject();
			}
			return obj;
		}
		
	}
}